package gold.digger;

import gold.utils.InputUtil;

import java.util.Random;

/**
 * Created by fanzhenyu02 on 2020/3/1.
 */
public class LC398 {


    public int[] arr;

    public LC398(int[] arr) {
        this.arr = arr;
    }

    public int pick(int target) {
        int cnt = 0, res = -1;
        Random random = new Random();
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == target) {
                res = random.nextInt(++cnt) == 0 ? i : res;
            }
        }

        return res;
    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 3, 3};
        LC398 an = new LC398(InputUtil.readLongArrayFromFile("program.txt"));
        System.out.println(an.pick(-760627172));
    }
}
